package 设计模式.基本原则.里氏代换原则.before;

public class Test {
    public static void main(String[] args) {
        changfangxing c = new changfangxing();
        c.setLength(10);
        c.setWidth(5);
        displayLength(c);
        //展示长方形
        resize(c);
        //扩宽
        displayLength(c);
        //再次展示

        /* 长为10.0
            宽为5.0
            长为10.0
            宽为11.0*/

        System.out.println("===================");
        zhengfangxing z = new zhengfangxing();
        z.setLength(10);
        displayLength(z);
        //展示长方形
        resize(z);
        //扩宽
        displayLength(z);
        //再次展示
    }

    public static void resize(changfangxing changfangxing) {
        //如果宽如果比长小,就把它扩宽
        while (changfangxing.getLength() >= changfangxing.getWidth()) {
            changfangxing.setWidth(changfangxing.getWidth() + 1);
        }

    }

    public static void displayLength(changfangxing c) {
        System.out.println("长为" + c.getLength());
        System.out.println("宽为" + c.getWidth());
    }
}
